package com.demo.unittest.springweb.util;

/**
 * @author tzp
 * @since 2018/5/23
 */
public class Base62Util {
    private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    public static int parse62To10(String originDigtal) {
        int result = 0;
        for (int i = 0; i < originDigtal.length(); i++) {
            char c = originDigtal.charAt(i);
            int index = CHARS.indexOf(c);
            result += index * Math.pow(62, originDigtal.length() - i - 1);
        }
        return result;
    }

    public static String parse10To62(int digit) {
        String result = "";
        int di = digit;
        while (di > 0) {
            int i = di % 62;
            result = CHARS.charAt(i) + result;
            di = di / 62;
        }
        return result;
    }
}
